package dao;
import java.util.List;

import org.hibernate.Transaction;
import org.hibernate.classic.Session;

import util.HibernateUtil;
import entity.CondicaoPagamento;
import entity.Marca;

public class CondicaoPagamentoDaoImplementation implements CondicaoPagamentoDao {

	public void save(CondicaoPagamento condicaoPagamento) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = session.beginTransaction();
		session.save(condicaoPagamento);
		transaction.commit();
		session.close();
	}

	public void update(CondicaoPagamento condicaoPagamento) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = session.beginTransaction();
		session.update(condicaoPagamento);
		transaction.commit();
		session.close();
	}

	public void delete(CondicaoPagamento condicaoPagamento) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = session.beginTransaction();
		session.delete(condicaoPagamento);
		transaction.commit();
		session.close();
	}

	public void consult(CondicaoPagamento condicaoPagamento) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = session.beginTransaction();
		condicaoPagamento = (CondicaoPagamento) session.load(CondicaoPagamento.class, new String("CondicaoPagamento"));
	}

	public CondicaoPagamento getCondicaoPagamento(long id) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		return (CondicaoPagamento) session.load(CondicaoPagamento.class, id);
	}
	
	public List<CondicaoPagamento> list() 
	{
	Session session = HibernateUtil.getSessionFactory().openSession();
	Transaction transaction = session.beginTransaction();
	String sql = "SELECT new CondicaoPagamento( c.idCondicaoPagamento, c.descricao, c.formaPagamento) FROM CondicaoPagamento c";
	List<CondicaoPagamento> lista = session.createQuery(sql).list();
	transaction.commit();
	session.close();
	return lista;
	}
	
	

}
